home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 98 / Skunkware 98.iso / src / net / bind-contrib.tar.gz / bind-contrib.tar / contrib / misc / checkdns.shar / checkDNS
Encoding:
Text File  |  1996-10-25  |  1.5 KB  |  67 lines

  1. #!/bin/sh
  2. # Script to check forward/reverse name mapping consistency
  3. # Author: Hans van Staveren <sater@cs.vu.nl>
  4. #
  5. PATH=/usr/local/bin:/usr/ucb:/usr/bin
  6. case $# in
  7. 0) echo "Usage: $0 [-p] [domain or network] ...";exit;
  8. esac
  9. ping=no
  10. case $1 in
  11. -p*)    ping=yes;shift;;
  12. esac
  13. for domain
  14. do
  15.     case $domain in
  16.     *[A-Za-z]*)
  17.     host -l $domain|sort -u|grep 'has address'|
  18.         grep -v -e '-net[0-9]'|grep -v localhost|
  19.     while read hostname has address ipaddr
  20.     do
  21.         revname=`host $ipaddr 2>/dev/null|sed -n 's/^Name: //p'`
  22.         if [ -z "$revname" ]
  23.         then revname="black-hole"
  24.         fi
  25.         hostname=`echo $hostname|tr '[A-Z]' '[a-z]'`
  26.         revname=`echo $revname|tr '[A-Z]' '[a-z]'`
  27.         if [ $hostname != $revname -a $revname != localhost ]
  28.         then echo "$hostname -> $ipaddr -> $revname"
  29.         fi
  30.         case $ping in
  31.         yes)
  32.             if /usr/etc/ping $hostname 5 >/dev/null 2>&1
  33.             then : nothing
  34.             else
  35.                 echo $hostname does not respond
  36.             fi
  37.             ;;
  38.         esac
  39.     done
  40.     ;;
  41.     *)
  42.     # Only class C style networks work currently
  43.     netdom=`echo $domain|sed 's/\(.*\)\.\(.*\)\.\(.*\)/\3.\2.\1/'`.in-addr.arpa
  44.     host -l $netdom|sort -u|grep '^[^0].* PTR '|
  45.     while read enc_ipaddr PTR hostname
  46.     do
  47.         ipaddr=`echo $enc_ipaddr|sed 's/\(.*\)\.\(.*\)\.\(.*\)\.\(.*\)\.IN.*/\4.\3.\2.\1/'`
  48.         if host $hostname 2>/dev/null|grep -s "has address $ipaddr"
  49.         then
  50.             : hunky dory
  51.         else
  52.             echo "$ipaddr -> $hostname, but no A record"
  53.         fi
  54.         case $ping in
  55.         yes)
  56.             if /usr/etc/ping $hostname 5 >/dev/null 2>&1
  57.             then : nothing
  58.             else
  59.                 echo $hostname does not respond
  60.             fi
  61.             ;;
  62.         esac
  63.     done
  64.     ;;
  65.     esac
  66. done
  67.